//
//  RBBrandSubCell.m
//  zhongzhenglu
//
//  Created by mac on 2022/12/15.
//

#import "RBBrandSubCell.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "RBThemeConfig.h"
#import <Masonry.h>
#import "RBTextField.h"
#import "UIButton+RBAdd.h"
#import <UIColor+YYAdd.h>
#import <NSDate+YYAdd.h>
#import "RBBrandResponse.h"
#import "UIImageView+RBAdd.h"

@interface RBBrandSubCell()

@property(nonatomic, strong)IBOutlet UIImageView *bgImgView;
@property(nonatomic, strong)IBOutlet UIView *brandView;
@property(nonatomic, strong)IBOutlet UILabel *brandL;
@property(nonatomic, strong)IBOutlet UILabel *desL;
@property(nonatomic, strong)IBOutlet UILabel *priceL;

@property(nonatomic, strong)IBOutlet UIView *leftGoodsView;
@property(nonatomic, strong)IBOutlet UIImageView *leftGoodsImgView;
@property(nonatomic, strong)IBOutlet UILabel *leftGoodsSaleL;
@property(nonatomic, strong)IBOutlet UILabel *leftGoodsPriceL;

@property(nonatomic, strong)IBOutlet UIView *rightGoodsView;
@property(nonatomic, strong)IBOutlet UIImageView *rightGoodsImgView;
@property(nonatomic, strong)IBOutlet UILabel *rightGoodsSaleL;
@property(nonatomic, strong)IBOutlet UILabel *rightGoodsPriceL;

@end

@implementation RBBrandSubCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self zoomSubViewsWithSelf];
    self.bgImgView.backgroundColor = UIColor.whiteColor;
    [self.bgImgView rbSetCornerRadius:Zoom(10)];
}

- (void)setCellModel:(RBCellModel *)cellModel
{
    RBBrandSubModel *model = cellModel.cellData;
    self.brandL.text = model.brand_name;
    self.desL.text = @"　";
    self.priceL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(15)] color:[UIColor colorWithHexString:@"#222222"] string:@"最低至"];
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(15)] color:[UIColor colorWithHexString:@"#EB0000"] string:model.price];
    }];
    NSArray *bgImgs = @[@"",@"brand8",@"brand6",@"brand7"];
    NSArray *brandBgColors = @[[UIColor colorWithHexString:@"#E9FFF4"],UIColor.whiteColor,UIColor.whiteColor,UIColor.whiteColor];
    NSArray *brandLColors = @[[UIColor colorWithHexString:@"#0C7C44"],[UIColor colorWithHexString:@"#EA4248"],[UIColor colorWithHexString:@"#1CC1D6"],[UIColor colorWithHexString:@"#354BEE"]];
    self.bgImgView.image = [UIImage imageNamed:bgImgs[model.displayType]];
    self.brandView.backgroundColor = brandBgColors[model.displayType];
    self.brandL.textColor = brandLColors[model.displayType];
    if(model.goods.count == 0)
    {
        self.leftGoodsView.hidden = YES;
        self.rightGoodsView.hidden = YES;
    }
    else if(model.goods.count == 1)
    {
        self.leftGoodsView.hidden = YES;
        self.rightGoodsView.hidden = NO;
        RBBrandSubGoodsModel *goodsModel = model.goods[0];
        [self.rightGoodsImgView setImageWithUrl:goodsModel.picurl placeHolder:nil];
        self.rightGoodsSaleL.text = [NSString stringWithFormat:@"已售%@台",goodsModel.sell_number];
        self.rightGoodsPriceL.text = [NSString stringWithFormat:@"¥%@",goodsModel.sell_price];
    }
    else
    {
        self.leftGoodsView.hidden = NO;
        self.rightGoodsView.hidden = NO;
        RBBrandSubGoodsModel *goodsModel = model.goods[0];
        [self.leftGoodsImgView setImageWithUrl:goodsModel.picurl placeHolder:nil];
        self.leftGoodsSaleL.text = [NSString stringWithFormat:@"已售%@台",goodsModel.sell_number];
        self.leftGoodsPriceL.text = [NSString stringWithFormat:@"¥%@",goodsModel.sell_price];
        goodsModel = model.goods[1];
        [self.rightGoodsImgView setImageWithUrl:goodsModel.picurl placeHolder:nil];
        self.rightGoodsSaleL.text = [NSString stringWithFormat:@"已售%@台",goodsModel.sell_number];
        self.rightGoodsPriceL.text = [NSString stringWithFormat:@"¥%@",goodsModel.sell_price];
    }
}

@end
